<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xml:lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"><head>

  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>java web开发 web.xml配置文件说明 - Tomcat - New - JavaEye论坛</title>
    <meta name="description" content="Tomcat中web.xml文件的详细说明 &lt;?xml version=&quot;1.0&quot; encoding=&quot;GB2312&quot;?&gt; &lt;!-- Web.xml依次定议了如下元素： &lt;web-app&gt; &lt;display-name&gt;&lt;/display-name&gt; 定义了WEB应用的名字 &lt;description&amp;g ...">
    <meta name="keywords" content=" Tomcat New">
    <link rel="shortcut icon" href="http://www.javaeye.com/images/favicon.ico" type="image/x-icon">
    <link href="http://www.javaeye.com/rss/board/New" rel="alternate" title="JavaEye论坛" type="application/rss+xml">
    <link href="347750_files/forum.css" media="screen" rel="stylesheet" type="text/css">
    <script src="347750_files/application.js" type="text/javascript"></script>
      <link href="347750_files/SyntaxHighlighter.css" media="screen" rel="stylesheet" type="text/css">
  <script src="347750_files/shCoreCommon.js" type="text/javascript"></script>
<script src="347750_files/hotkey.js" type="text/javascript"></script>
          <script src="347750_files/dragdrop.js" type="text/javascript"></script>
          </head><body>
    <div id="page">
      <div id="header">
        <div class="clearfix"><div id="user_nav">
      <a href="http://www.javaeye.com/login" class="welcome" title="登录">您还未登录 !</a>
    <a href="http://www.javaeye.com/all" style="color: red;">我的应用</a>
    <a href="http://www.javaeye.com/login">登录</a>
    <a href="http://www.javaeye.com/signup" class="nobg">注册</a>
  </div></div>
        <div class="clearfix">
          <div id="branding">
            <a href="http://www.javaeye.com/"><img alt="JavaEye-最棒的软件开发交流社区" src="347750_files/logo.gif" title="JavaEye-最棒的软件开发交流社区"></a>
          </div>
          <div id="ad"><img src="347750_files/banner.jpg"></div>
        </div>
      </div>

      <div id="content" class="clearfix">
        <div id="main">
          


          

<div class="clearfix">
  <div class="crumbs">
    <a href="http://www.javaeye.com/forums">论坛首页</a> <span class="arrow">→</span>
    <a href="http://www.javaeye.com/forums/board/New">入门讨论版</a> <span class="arrow">→</span>
    <a href="http://www.javaeye.com/forums/tag/Tomcat">Tomcat</a> <span class="arrow">→</span>
    <h1>java web开发 web.xml配置文件说明</h1>
  </div>
</div>

<div id="forum_tag_list">
  <a href="http://www.javaeye.com/forums/board/New">全部</a>
      <a href="http://www.javaeye.com/forums/tag/Newbie">入门技术</a>
  </div>

<div class="actions">
  <div class="buttons"><a href="http://www.javaeye.com/forums/46/topics/347750/posts/new" class="new_post" title="发表回复">&nbsp;</a></div>
  <div class="wrapper">
    <div id="forum_advert_f4"></div>
    
    <div class="info">浏览 641 次</div>
  </div>
</div>



<table id="forum_main" cellspacing="1">
  <thead>
    <tr>
      <th colspan="2" class="topic_title">
        <div class="wrapper"> <a href="http://www.javaeye.com/topic/347750">主题：java web开发 web.xml配置文件说明</a></div>
        <div id="topic_rate_box">精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)</div>
      </th>
    </tr>
    <tr>
      <td class="first_col">作者</td>
      <td class="last_col">正文</td>
    </tr>
  </thead>
  <tbody id="posts">
    <tr id="922231">
  <td class="postauthor">
    <ul>
      <li class="name">xmfish</li>
      <li>等级: 初级会员</li>
      <li><a href="http://xmfish.javaeye.com/" target="_blank"><img alt="xmfish的博客" class="logo" src="347750_files/user-logo.gif" title="xmfish的博客: "></a></li>
      <li>文章: 2</li>
      <li>积分: 40</li>
      <li>来自: 上海</li>
      <li><img src="347750_files/offline.gif"></li>
    </ul>
  </td>
  <td class="postcontent">
    <div class="postactions">
      <div class="description">
        发表时间：2009-03-11
        
      </div>
      <div class="links">
        
      </div>
    </div>
    <div class="postbody clearfix">
                                            <div style="position: relative;" id="related_topics">相关文章: <span class="close"><a href="#" onclick="$('related_topics').hide();return false;" title="关闭">&nbsp;</a></span>
              <ul>
                                    <li><a href="http://www.javaeye.com/topic/3373" title="有谁知道tomcat如何初始化DBCP的？" target="_blank">有谁知道tomcat如何初始化DBCP的？</a></li>
                                      <li><a href="http://www.javaeye.com/topic/10296" title="spring入门编程问题集锦" target="_blank">spring入门编程问题集锦</a></li>
                                      <li><a href="http://www.javaeye.com/topic/312870" title="struts1.2与spring整合手记" target="_blank">struts1.2与spring整合手记</a></li>
                                  </ul>
                <br><span>推荐圈子: <a href="http://ecside.group.javaeye.com/" target="_blank">GT-Grid</a></span>
                <br><a href="http://www.javaeye.com/wiki/topic/347750" target="_blank">更多相关推荐</a>
              </div>
              <script type="text/javascript">
                new Draggable("related_topics");
              </script>
                              
        <p>Tomcat中web.xml文件的详细说明 <br>&lt;?xml version="1.0" encoding="GB2312"?&gt; &lt;!-- <br>Web.xml依次定议了如下元素： <br>&lt;web-app&gt; <br>&lt;display-name&gt;&lt;/display-name&gt; 定义了WEB应用的名字 <br>&lt;description&gt;&lt;/description&gt; 声明WEB应用的描述信息 <br>&lt;filter&gt;&lt;/filter&gt; <br>&lt;filter-mapping&gt;&lt;/filter-mapping&gt; <br>&lt;servlet&gt;&lt;/servlet&gt; <br>&lt;servlet-mapping&gt;&lt;/servlet-mapping&gt; <br>&lt;session-config&gt;&lt;/session-config&gt; <br>&lt;welcome-file-list&gt;&lt;/welcome-file-list&gt; <br>&lt;taglib&gt;&lt;/taglib&gt; <br>&lt;resource-ref&gt;&lt;/resource-ref&gt; <br>&lt;security-constraint&gt;&lt;/security-constraint&gt; <br>&lt;login-config&gt;&lt;/login-config&gt; <br>&lt;/web-app&gt; <br>在web.xml中元素定义的先后顺序不能颠倒，否则Tomcat服务器可能会抛出SAXParseException. <br>--&gt; <br>&lt;!DOCTYPE web-app PUBLIC "-//Sun Microsystems,Inc.//DTD Web Application 2.3//EN" "<a href="http://java.sun.com/dtd/web-app_2_3.dtd">http://java.sun.com/dtd/web-app_2_3.dtd</a>"&gt; <br>&lt;web-app&gt; </p>
<p>&lt;display-name&gt;Sample Application&lt;/display-name&gt; </p>
<p>&lt;description&gt; <br>This is a Sample Application <br>&lt;/description&gt; </p>
<p>&lt;!-- <br>filter 配置Servlet过滤器 <br>filter-name 定义过滤器的名字。当有多个过滤器时，不能同名 <br>filter-class 指定实现这一过滤的类，这个类负责具体的过滤事务 <br>--&gt; <br>&lt;filter&gt; <br>&lt;filter-name&gt;SampleFilter&lt;/filter-name&gt; <br>&lt;filter-class&gt;mypack.SampleFilter&lt;/filter-class&gt; <br>&lt;/filter&gt; </p>
<p>&lt;!-- <br>filter-mapping 设定过滤器负责过滤的URL <br>filter-name 过滤器名。这里的名字一定要和filter中的过滤器名匹配 <br>url-pattern 指定过滤器负责过滤的URL <br>--&gt; <br>&lt;filter-mapping&gt; <br>&lt;filter-name&gt;SampleFilter&lt;/filter-name&gt; <br>&lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt; <br>&lt;/filter-mapping&gt; </p>
<p>&lt;!-- <br>servlet 配置Servlet. <br>servlet-name 定义Servlet的名字 <br>servlet-class 指定实现这个servlet的类 <br>init-param 定义Servlet的初始化参数和参数值，可有多个init-param。在servlet类中通过getInitParamenter(String name)方法访问初始化参数 <br>load-on-startup 指定当Web应用启动时，装载Servlet的次序。 <br>当值为正数或零时：Servlet容器先加载数值小的servlet，再依次加载其他数值大的servlet. <br>当值为负或未定义：Servlet容器将在Web客户首次访问这个servlet时加载它 <br>--&gt; <br>&lt;servlet&gt; <br>&lt;servlet-name&gt;SampleServlet&lt;/servlet-name&gt; <br>&lt;servlet-class&gt;mypack.SampleServlet&lt;/servlet-class&gt; <br>&lt;init-param&gt; <br>&lt;param-name&gt;initParam1&lt;/param-name&gt; <br>&lt;param-value&gt;2&lt;/param-value&gt; <br>&lt;/init-param&gt; <br>&lt;load-on-startup&gt;1&lt;/load-on-startup&gt; <br>&lt;/servlet&gt; </p>
<p>&lt;!-- <br>配置servlet映射（下面代码为SampleServlet指定的相对URL为"/sample": <br>servlet-name 指定servlet的名字，这里的名字应该和&lt;Servlet&gt;元素中定义的名字匹配。 <br>url-pattern 指定访问这个servlet的URL。只需给出相对路径。 <br>--&gt; <br>&lt;servlet-mapping&gt; <br>&lt;servlet-name&gt;SampleServlet&lt;/servlet-name&gt; <br>&lt;url-pattern&gt;/sample&lt;/url-pattern&gt; <br>&lt;/servlet-mapping&gt; </p>
<p>&lt;!--配置session session用来设定HttpSession的生命周期。单位（秒）--&gt; <br>&lt;session-config&gt; <br>&lt;session-timeout&gt;30&lt;/session-timeout&gt; <br>&lt;/session-config&gt; </p>
<p>&lt;!--配置Wel0come0文件清单--&gt; <br>&lt;welcome-file-list&gt; <br>&lt;welcome-file&gt;login.jsp&lt;/welcome-file&gt; <br>&lt;welcome-file&gt;index.htm&lt;/welcome-file&gt; <br>&lt;/welcome-file-list&gt; </p>
<p>&lt;!-- <br>配置Tag Library <br>taglib-uri 设定Tag Library的唯一标识符，在Web应用中将根据这一标识符来引用Tag Library <br>taglib-location 指定和Tag Library对应的TLD文件的位置 <br>--&gt; <br>&lt;taglib&gt; <br>&lt;taglib-uri&gt;/mytaglib&lt;/taglib-uri&gt; <br>&lt;taglib-location&gt;/WEB-INF/mytaglib.tld&lt;/taglib-location&gt; <br>&lt;/taglib&gt; </p>
<p>&lt;!-- <br>配置资源引用 <br>description 对所引用的资源的说明 <br>res-ref-name 指定所引用资源的JNDI名字 <br>res-type 指定所引用资源的类名字 <br>res-auth 指定管理所引用资源的Manager,它有两个可选值： <br>Container：由容器来创建和管理resource <br>Application:同WEB应用来创建和管理Resource <br>--&gt; <br>&lt;resource-ref&gt; <br>&lt;description&gt;DB Connection&lt;/description&gt; <br>&lt;res-ref-name&gt;jdbc/sampleDB&lt;/res-ref-name&gt; <br>&lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt; <br>&lt;res-auth&gt;Container&lt;/res-auth&gt; <br>&lt;/resource-ref&gt; </p>
<p>&lt;!-- <br>配置安全约束（以下代码指定当用户访问该WEB应用下的所有资源时，必须具备guest角色） <br>web-resource-collection 声明受保护的WEB资源 <br>auth-constraint 声明可以访问受保护资源的角色，可以包含多个&lt;role-name&gt;子元素 </p>
<p>web-resource-name 标识受保护的WEB资源 <br>url-pattern 指定受保护的URL路径 <br>--&gt; <br>&lt;Security-constraint&gt; <br>&lt;web-resource-collection&gt; <br>&lt;web-resource-name&gt;sample appliction&lt;/web-resource-name&gt; <br>&lt;url-pattern&gt;/*&lt;/url-pattern&gt; <br>&lt;/web-resource-collection&gt; <br>&lt;auth-constraint&gt; <br>&lt;role-name&gt;guest&lt;/role-name&gt; <br>&lt;/auth-constraint&gt; <br>&lt;/Security-constraint&gt; </p>
<p><br>&lt;!-- <br>配置安全验证登录界面：指定当WEB客户访问受保护的WEB资源时，系统弹出的登录对话框的类型。 <br>auth-method 指定验证方法，它有三个可选值：BASIC(基本验证)、DIGEST(摘要验证)、FORM(表单验证) <br>realm-name 设定安全域的名称 <br>form-login-config 当验证方法为FORM时，配置验证网页和出错网页 <br>form-login-page 当验证方法为FORM时，设定验证网页 <br>form-error-page 当验证方法为FORM时，设定出错网页 <br>--&gt; <br>&lt;login-config&gt; <br>&lt;auth-method&gt;FORM&lt;/auth-method&gt; <br>&lt;realm-name&gt; <br>Tomcat Server Configuration form-Based Authentication Area <br>&lt;/realm-name&gt; <br>&lt;form-login-config&gt; <br>&lt;form-login-page&gt;/login.jsp&lt;/form-login-page&gt; <br>&lt;form-error-page&gt;/error.jsp&lt;/form-error-page&gt; <br>&lt;/form-login-config&gt; <br>&lt;/login-config&gt; </p>
<p>&lt;!--配置对安全验证角色的引用--&gt; <br>&lt;security-role&gt; <br>&lt;description&gt; <br>The role that is required to log into the sample application <br>&lt;/description&gt; <br>&lt;role-name&gt;guest&lt;/role-name&gt; <br>&lt;/security-role&gt; <br>&lt;/web-app&gt; </p>
      </div>

              <div id="forum_advert_f0"><script type="text/javascript">
google_ad_client = "pub-9971846879634397";
google_ad_slot = "6749798418";
google_ad_width = 728;
google_ad_height = 90;
</script>
<script type="text/javascript" src="347750_files/show_ads.js">
</script><script src="347750_files/expansion_embed.js"></script><script src="347750_files/test_domain.js"></script><script>google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);</script><ins style="border: medium none ; margin: 0pt; padding: 0pt; display: inline-table; height: 90px; position: relative; visibility: visible; width: 728px;"><ins style="border: medium none ; margin: 0pt; padding: 0pt; display: block; height: 90px; position: relative; visibility: visible; width: 728px;"><iframe allowtransparency="true" hspace="0" id="google_ads_frame1" marginheight="0" marginwidth="0" name="google_ads_frame" src="347750_files/ads.htm" style="left: 0pt; position: absolute; top: 0pt;" vspace="0" width="728" frameborder="0" height="90" scrolling="no"></iframe></ins></ins></div>
      
      

              <div id="topic_copyright">声明：JavaEye文章版权属于作者，受法律保护。没有作者书面许可不得转载。 </div>
        <div id="forum_advert_f5"><span>推荐链接</span><ul class="adverts"><li><a href="http://www.javaeye.com/clicks/111" target="_blank"><img src="347750_files/720-60.gif" style="border: 1px solid rgb(255, 255, 255);" alt="taobao，赢在淘宝" title="taobao，赢在淘宝" width="720" height="60"></a></li><li><a href="http://www.javaeye.com/clicks/170" target="_blank"><span style="color: blue; font-weight: bold;"> 【8月推荐】JAVA技术沙龙活动通知--欢迎并期待您的参与!</span></a></li></ul></div>
          </td>
  </tr>
  <tr>
    <td class="postauthor"><a href="#">返回顶楼</a></td>
    <td class="postcontent">
      <div class="icons">
        <a href="http://xmfish.javaeye.com/" class="icon_www" title="浏览作者的博客">&nbsp;</a>
        <a href="http://xmfish.javaeye.com/blog/profile" class="icon_profile" title="浏览作者资料">&nbsp;</a>
        <a href="http://app.javaeye.com/messages/new?message%5Breceiver_name%5D=xmfish" class="icon_pm" title="发送站内短信">&nbsp;</a>
        <a href="http://xmfish.javaeye.com/blog/guest_book" class="icon_guestbook" title="给作者留言">&nbsp;</a>
        
                
      </div>
                        </td>
  </tr>
  <tr class="sep2"><td colspan="2"></td></tr>

  </tbody>
</table>


<div class="actions">
  <div class="buttons"><a href="http://www.javaeye.com/forums/46/topics/347750/posts/new" class="new_post" title="发表回复">&nbsp;</a></div>
  <div class="wrapper"></div>
</div>

<div>
  <div class="crumbs">
    <a href="http://www.javaeye.com/forums">论坛首页</a> <span class="arrow">→</span>
    <a href="http://www.javaeye.com/forums/board/New">入门讨论版</a>
     <span class="arrow">→</span> <a href="http://www.javaeye.com/forums/tag/Tomcat">Tomcat</a>
    <br><br>跳转论坛:<select id="forum_urlname" name="forum[urlname]" onchange="window.location='/forums/board/'+this.value"><option value="Java">Java编程和Java企业应用</option>
<option value="web">Web前端技术：AJAX和RIA</option>
<option value="mobile">移动编程和手机应用开发</option>
<option value="Ruby">Ruby</option>
<option value="Python">Python</option>
<option value="PHP">PHP</option>
<option value="Flash">Flash编程</option>
<option value="dotnet">Microsoft .Net</option>
<option value="Tech">综合技术</option>
<option value="New" selected="selected">入门讨论</option>
<option value="develop">软件开发和项目管理</option>
<option value="Industry">行业应用</option>
<option value="vendor">厂商论坛</option>
<option value="Job">招聘求职</option>
<option value="Life">海阔天空</option></select>
    <div id="forum_advert_f6"></div>
  </div>

  
</div>

<div style="display: none;">
  <form action="/posts/rate" id="post_rate_form" method="post" onsubmit="new Ajax.Request('/posts/rate', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">
    <input id="post_rate_id" name="id" type="hidden">
    <input id="post_rate_type" name="type" type="hidden">
  </form></div>

<script type="text/javascript">
  dp.SyntaxHighlighter.HighlightAll('code', true, true);

  fix_image_size($$('div.postbody img'), 760);

  function rate_post(id, type) {
    Element.update('post_rate_box_' + id, '提交中...');
    new Ajax.Request('/posts/rate', {asynchronous:true, evalScripts:true, parameters:{"id":id, "type":type}});
  }

  function rate_topic(type) {
    Element.update('topic_rate_box', '提交中...');
    new Ajax.Request('/topics/rate', {asynchronous:true, evalScripts:true, parameters:{"id":347750, "type":type}});
  }
</script>


        </div>
        <div id="nav">
  <div class="wrapper">
    <ul>
            <li><a href="http://www.javaeye.com/">首页</a></li>
      <li><a href="http://www.javaeye.com/news">新闻</a></li>
      <li><a href="http://www.javaeye.com/forums" class="selected">论坛</a></li>
      <li><a href="http://www.javaeye.com/ask">问答</a></li>
      <li><a href="http://www.javaeye.com/wiki">知识库</a></li>
      <li><a href="http://www.javaeye.com/blogs">博客</a></li>
      <li><a href="http://www.javaeye.com/groups">圈子</a></li>
      <li><a href="http://www.javaeye.com/job">招聘</a></li>
      <li><a href="http://www.javaeye.com/index/service">服务</a></li>
      <li class="last"><a href="http://www.javaeye.com/search">搜索</a></li>
    </ul>
  </div>
</div>

<div id="channel_nav">
  <ul>
    <li><a href="http://java.javaeye.com/">Java</a></li>
    <li><a href="http://web.javaeye.com/">Web</a></li>
    <li><a href="http://ruby.javaeye.com/">Ruby</a></li>
    <li><a href="http://python.javaeye.com/">Python</a></li>
    <li><a href="http://agile.javaeye.com/">敏捷</a></li>
    <li><a href="http://mysql.javaeye.com/">MySQL</a></li>
    <li><a href="http://primeton.javaeye.com/">普元</a></li>
    <li><a href="http://dorado.javaeye.com/">Dorado</a></li>
    <!--li><a href="http://kingdee.javaeye.com" >金蝶中间件</a></li-->
    <li class="last"><a href="http://book.javaeye.com/">图书</a></li>
  </ul>
</div>
      </div>
      <div id="footer">
  <div id="site_nav">
    <ul>
      <li><a href="http://www.javaeye.com/index/service">广告服务</a></li>
      <li><a href="http://webmaster.javaeye.com/">JavaEye黑板报</a></li>
      <li><a href="http://www.javaeye.com/index/aboutus">关于我们</a></li>
      <li><a href="http://www.javaeye.com/index/contactus">联系我们</a></li>
      <li class="last"><a href="http://www.javaeye.com/index/friend_links">友情链接</a></li>
    </ul>
  </div>
  <div id="copyright">
    © 2003-2009 JavaEye.com.   All rights reserved. 上海炯耐计算机软件有限公司 [ 沪ICP备05023328号 ] 
  </div>
</div>

    </div>
    
<script type="text/javascript">
  document.write("<img src='http://stat.javaeye.com/?url="+ encodeURIComponent(document.location.href) + "&referrer=" + encodeURIComponent(document.referrer) + "&logged_in=no" + "' width='0' height='0' />");
</script><img src="347750_files/a.gif" width="0" height="0">
  </body></html>